<template>
  <ui-page showTabbar>
    <view class="content">
      <biz-switch-env-config ref="bizSwitchEnvConfigRef" />
      <image class="logo" src="../../static/logo.png"></image>
      <u-button>{{
        `登陆状态---   ${store.isLogin ? '已登陆' : '未登录'}`
      }}</u-button>
      <u-button @click="click">切换环境</u-button>
      <u-button @click="getUrl">查询当前接口地址</u-button>
      <u-button @click="getList">发起请求</u-button>
      <u-button @click="go(1)">跳转页面</u-button>
      <u-button @click="go(2)">跳转页面传参数</u-button>
      <u-button @click="go(3)">跳转页面传参数</u-button>
      <u-button @click="go(4)">重定向当前页(带参)</u-button>
      <u-button @click="login">登陆失效</u-button>
      <u-button @click="store.addCount">{{ `pinia(${store.count})` }}</u-button>
      <u-input
        placeholder="请输入内容"
        border="surround"
        v-model="value"
        customStyle="border:1px solid red !important"
      ></u-input>
    </view>
  </ui-page>
</template>

<script setup>
import { ApiUrl } from '@/config/api'
import { ENV } from '@/config'
// 全局onLoad，onShow
import { usePageCycle } from '@/composables/global.js'
import { useUserStore } from '@/store/modules/user'

usePageCycle()

let store = useUserStore()

const login = () => {
  uni.$emit('needLogin', true)
  console.log(uni.$getCurRouter())
}
// 跳转传参
const go = (e) => {
  let go = uni.$navTo
  let fun = {
    1: () => go(2, 'pages1/index1/index1'),
    2: () => go(2, { path: 'pages1/index1/index1', query: { data: 999 } }),
    3: () => go(2, 'pages1/index1/index1?data=8888'),
    4: () => uni.$navToCurrentPage({ data: 999 })
  }
  fun[e]()
}

const getList = () => {
  uni.$Api.fetchUserInfo()
}

const value = ref()

const bizSwitchEnvConfigRef = ref()

const click = () => {
  bizSwitchEnvConfigRef.value.openSetEnv()
}

const getUrl = () => {
  console.log(
    `%c 编译环境::::::  %c  ${ENV}  %c 切换的接口地址::::::  %c ${ApiUrl}`,
    'color: #ffffff; background: #3c9cff; padding:5px 0;',
    'padding:5px 0;',
    'color: #ffffff; background: #3c9cff; padding:5px 0;',
    'padding:5px 0;'
  )
}
// #ifdef APP-PLUS
onShow(() => {
  uni.hideTabBar({
    success: () => {
      console.log('隐藏成功onLaunch')
    },
    fail: () => {
      console.log('隐藏失败onLaunch')
    }
  })
})

// #endif
</script>

<style>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 200rpx;
  width: 200rpx;
  margin-top: 200rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 50rpx;
}

.text-area {
  display: flex;
  justify-content: center;
}

.title {
  font-size: 36rpx;
  color: #8f8f94;
}
</style>
